<?php
namespace mobile\controllers;

use frontend\models\ArtForm;
use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\helpers\Url;
use yii\web\Controller;
use yii\web\Response;
use yii\base\ErrorException;
use yii\helpers\Html;
use common\models\member\Member;
use common\models\category\Category;
use common\models\articles\Articles;
use common\models\Fenhuigrade\Fenhuigrade;
use yii\data\Pagination;

class ContentController extends Controller
{    
    /*
	*   联系我们内容单页
	*/ 
	public function actionIndex($id){

	 	/*if(Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['parent_id'] == 0){
	 		$childcat = Category::find()->where(['status'=> 1, 'parent_id'=> $id])->asArray()->all();
			$tid = $id;
	 		$id = $childcat[0]['id'];
			$parenttitle = Category::find()->where(['status'=> 1, 'id'=> $tid])->asArray()->one()['name'];
	 	}else{
	 		$parentid = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['parent_id'];
			$tid = $parentid;
	 		$childcat = Category::find()->where(['status'=> 1, 'parent_id'=> $parentid])->asArray()->all();
			$parenttitle = Category::find()->where(['status'=> 1, 'id'=> $parentid])->asArray()->one()['name'];
	 	}

	 	$parentinfo = Category::find()->where(['status'=> 1, 'id'=> $tid])->asArray()->one();
	 	$title = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['name'];*/
	 	if(Category::find()->where(['id'=> $id])->asArray()->one()['parent_id'] == 0){
	 		$childcat = Category::find()->where(['parent_id'=> $id])->asArray()->all();
			$tid = $id;
	 		$id = $childcat[0]['id'];
			$parenttitle = Category::find()->where(['id'=> $tid])->asArray()->one()['name'];
	 	}else{
	 		$parentid = Category::find()->where(['id'=> $id])->asArray()->one()['parent_id'];
			$tid = $parentid;
	 		$childcat = Category::find()->where(['parent_id'=> $parentid])->asArray()->all();
			$parenttitle = Category::find()->where(['id'=> $parentid])->asArray()->one()['name'];
	 	}

	 	$parentinfo = Category::find()->where(['id'=> $tid])->asArray()->one();
	 	$title = Category::find()->where(['id'=> $id])->asArray()->one()['name'];
	 	$articles = Articles::find()->where(['category_id'=>$id])->asArray()->one();

        $view = Yii::$app->view;
        $view->params['title']=$title;

        return $this->render('index',[
		    'parentid'=>$tid,
        	'id' => $id,
        	'title' => $title,
        	'parentinfo' => $parentinfo,
			'parenttitle'=>$parenttitle,
            'childcat' => $childcat,
            'articles' => $articles,
        ]);
   	}

    /*
	*   分会单页
	*/ 
   	public function actionFenhui($id){

   		$article = Fenhuigrade::find()->where(['id' => $id])->asArray()->one();
   		$childcat = Fenhuigrade::find()->asArray()->all();
   		$parenttitle = "协会机构";
	 	$title = $article['name'];
	 	// 判断页面右侧内容块样式
	 	$parentid = 1;
        return $this->render('fenhui',[
        	'id' => $id,
        	'title' => $title,
			'parenttitle'=>$parenttitle,
            'article' => $article,
            'childcat' => $childcat,
            'parentid' => $parentid,
        ]);
   	}
	
    /*
	*   网站地图
	*/ 
   	public function actionDitu(){
		$view = Yii::$app->view;
        $view->params['title']='网站地图';

        return $this->render('ditu',[
		
        ]);
   	}


}